package cn.bb.test;

import cn.bb.dao.UserDao;
import cn.bb.dao.UserTemplateDao;
import cn.bb.pojo.User;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.test.context.TestExecutionListeners;

import java.util.List;

public class Demo {
    ApplicationContext app = null;
    @Before
    public void init(){
        app = new ClassPathXmlApplicationContext("spring.xml");
    }
    @Test
    public void test1(){
        //ApplicationContext app = new ClassPathXmlApplicationContext("spring.xml");
        UserDao user = app.getBean("userDao",UserDao.class);
        List<User> list = user.searchUser();
        for (User user1 : list) {
            System.out.println(user1.getName());
        }
    }
    @Test
    public void test2(){
        UserTemplateDao us = app.getBean("userTemp", UserTemplateDao.class);
        User user = new User();
        user.setName("bcd");
        user.setPwd("123456");
        System.out.println(us.addUser(user));
    }
    @Test
    public  void test3(){
        UserTemplateDao us = app.getBean("userTemp", UserTemplateDao.class);
        List<User> list = us.search();
        for (User user : list) {
            System.out.println(user.getId()+","+user.getPwd());
        }
    }
    @Test
    public  void test4(){
        UserTemplateDao us = app.getBean("userTemp", UserTemplateDao.class);
        User users = us.getById(1);
        System.out.println(users.getPwd());
    }

}
